home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / morse / dspmorse / morse.dsk (.txt) < prev    next >
Turbo C Context File  |  1994-01-17  |  25KB  |  828 lines

  1. Turbo C Context File 
  2. MORSE.C
  3. VID.C
  4. *.CPP
  5. C:\CWORK\MORSE\SB.C
  6. C:\CWORK\MORSE\MORSE.C
  7. C:\CWORK\MORSE\MORSE.H
  8. \        for (c=41; c<GRAPHTOP; c++)
  9.             if        (c<BLU)    col=9;
  10.             else if (c<GRN)    col=10;
  11.             else if (c<YEL)    col=14;
  12.             else            col=12;
  13.             pokeb(VIDSEG,l160+(c<<1),0xFA);
  14.             if (VIDSEG==0xB800)
  15.                 pokeb(VIDSEG,l160+(c<<1)+1,col);
  16. void wputc(char c, char move)
  17.     static int x=1, y=1;
  18.     pokeb(VIDSEG,(x<<1)+(y*160), c);
  19.     if (move)
  20.         x++;
  21.         if (x>=35)
  22.             y++;
  23.             if (y>=24)
  24.                 y=1;
  25.                 for (x=1; x<35; x++)
  26.                 {
  27.                     pokeb(VIDSEG,(x<<1)+(y*160),' ');
  28.                 }
  29.             x=1;
  30. void clrGraph(void)
  31.     int l, c, col, l160;
  32.     for (l=0,l160=0; l<(N-1); l++,l160+=160)
  33.         for (c=41; c<GRAPHTOP; c++)
  34.             if        (c<BLU)    col=9;
  35.             else if (c<GRN)    col=10;
  36.             else if (c<YEL)    col=14;
  37.             else            col=12;
  38.             pokeb(VIDSEG,l160+(c<<1),0xFA);
  39.             if (VIDSEG==0xB800)
  40.                 pokeb(VIDSEG,l160+(c<<1)+1,col);
  41. /////////////////////////////////////////////////////////////////////////////
  42.                                         // Display CT-VOICE.DRV version.
  43.     _BX = 0;
  44.     (*driver)();
  45.     ver = _AX;
  46.     printf("\nCT-VOICE.DRV version %d.%d.", (ver>>8)&0xFF, ver&0xFF);
  47. void clrGraph(void)
  48.     int l, c, col, l160;
  49.     for (l=0,l160=0; l<(N-1); l++,l160+=160)
  50.         for (c=41; c<GRAPHTOP; c++)
  51.             if        (c<BLU)    col=9;
  52.             else if (c<GRN)    col=10;
  53.             else if (c<YEL)    col=14;
  54.             else            col=12;
  55.             pokeb(VIDSEG,l160+(c<<1),0xFA);
  56.             pokeb(VIDSEG,l160+(c<<1)+1,col);
  57.     int l, c, col, l160;
  58.     sbOpen();
  59.     printf("\nSetStat: %d", sbSetStatWord(&sbstat));
  60.     printf("\nRecSrc : %d", sbSetRecSrc(3));    // line in
  61.     printf("\nRecMode: %d", sbSetRecMode(0));        // mono
  62.     printf("\nSpkOnOf: %d", sbSpeaker(1));    // turn on speaker
  63.                                         // Set up the Sound Blaster, and
  64.                                         // display (although briefly) some
  65.                                         // interesting information about it.
  66.     sbOpen();
  67.     printf("\nSetStat: %d", sbSetStatWord(&sbstat));
  68.     printf("\nRecSrc : %d", sbSetRecSrc(3));    // line in
  69.     printf("\nRecMode: %d", sbSetRecMode(0));        // mono
  70.     printf("\nSpkOnOf: %d", sbSpeaker(1));    // turn on speaker
  71.     bufone = (char far *)farmalloc(SAMPLELEN+0x40);
  72.     buftwo = (char far *)farmalloc(SAMPLELEN+0x40);
  73.     if ((bufone==NULL) || (buftwo==NULL))
  74.         puts("Woops!  No room for buffers!");
  75.         goto quickdone;
  76.     bufone = MK_FP(FP_SEG(bufone)+1,0);
  77.     buftwo = MK_FP(FP_SEG(buftwo)+1,0);
  78. #define KCHECK 64 /* ratio of key pressed checks versus FFT cycles  */
  79. #define SCHECK 16 /* ratio of sampling rate checks versus key checks */
  80. #define SAMPSTRING "%d S-Blaster Samples per Second  "
  81. #define STATSTRING "Avrg Dot:%d  Avrg Dash:%d (* resets) "
  82. static int code=0;
  83. static int mask=1;
  84. UINT sbstat;
  85. char far *bufone=NULL; char far *bufin=NULL;
  86. char far *buftwo=NULL; char far *bufdsp=NULL; char far *bi;
  87. char far *bufone=NULL; char far *bufin=NULL;
  88. char far *buftwo=NULL; char far *bufdsp=NULL; char far *bi;
  89. static int done=FALSE;
  90. static int done=FALSE;
  91. int dspcount;
  92.             pokeb(VIDSEG,80+line+(maxlevel[l]<<1),0x07);
  93.                                         // The limit is a function of the
  94.                                         // calc limit
  95.     limit=flip+(5*average);
  96.                                         // The limit is a function of the
  97.                                         // calc limit
  98.     limit=flip+(5*average);
  99.                                         // Update the average display if this
  100.                                         // average signal is different than
  101.                                         // the last.
  102.     if (average != oldavg)
  103.         pokeb(VIDSEG, 2482+(oldavg<<1), 0x20);
  104.         pokeb(VIDSEG, 2482+(average<<1), 0xB3);
  105.         average = limit;
  106.         pokeb(VIDSEG, 2482+(average<<1), ((average==focavg)?(0xBA):(0xB3)));
  107.         pokeb(VIDSEG, 2482+(focavg<<1), ((average==focavg)?(0xBA):(0xB3)));
  108.     pokeb(VIDSEG, 2482+(oldlimit<<1), 0x20);
  109.                                         // The limit is a function of the
  110.                                         // calc limit
  111.     limit=flip+(5*average);
  112.     static int focAvg[M];
  113.     totFFT[0] = avgFFT[0][1];
  114.     totFFT[00] = avgFFT[0][00];
  115.     totFFT[00] -= avgFFT[0,00];
  116.     totFFT[00] -= avgFFT[0,00];
  117.     totFFT[01] -= avgFFT[0,01];
  118.     totFFT[02] -= avgFFT[0,02];
  119.     totFFT[03] -= avgFFT[0,03];
  120.     totFFT[04] -= avgFFT[0,04];
  121.     totFFT[05] -= avgFFT[0,05];
  122.     totFFT[06] -= avgFFT[0,06];
  123.     totFFT[07] -= avgFFT[0,07];
  124.     totFFT[08] -= avgFFT[0,08];
  125.     totFFT[09] -= avgFFT[0,09];
  126.     totFFT[10] -= avgFFT[0,10];
  127.     totFFT[11] -= avgFFT[0,11];
  128.     totFFT[12] -= avgFFT[0,12];
  129.     totFFT[13] -= avgFFT[0,13];
  130.     totFFT[14] -= avgFFT[0,14];
  131. static    char        fft[N*MAXFFT];        // FFT buffer for smoothing
  132. static    char        fft[N*MAXFFT];        // scaled FFT buffer for smoothing
  133.     totFFT[00] -= fft[0][00];
  134. char                cntFFT=1;            // number of FFT thangs to track
  135.     totFFT[09] +=
  136.     avgFFT[00] =
  137.         ) / cntFFT;
  138. fft[0][00]
  139. fft[0][00];
  140. static    char        fft[MAXFFT][N];        // scaled FFT buffer for smoothing
  141. static    char        fft[MAXFFT][N];        // scaled FFT buffer for smoothing
  142. UINT                totFFT[N-1];        // total of the smoothed FFT thang
  143. char                oldFFT[N-1];        // last smoothed FFT thing
  144. char                avgFFT[N-1];        // average FFT over cntFFT iterations
  145.         ) / cntFFTp1;
  146.   123456789-123456789-123456789-12345678
  147. 1|oFreq: 12345       oSmooth: 333
  148. 2|oSkip: 12
  149. static unsigned int sbSampleRate = SAMPLEMAX;
  150. 17    1|(QW) Freq: 12345    (ER) Smooth: 333
  151. 18    2|(AS) Skip: 12
  152.                         clearGraph();
  153.     for (l=0,l160=0; l<(N-1); l++,l160+=160)
  154.         for (c=41; c<GRAPHTOP; c++)
  155.             if        (c<BLU)    col=9;
  156.             else if (c<GRN)    col=10;
  157.             else if (c<YEL)    col=14;
  158.             else            col=12;
  159.             pokeb(VIDSEG,l160+(c<<1),0xFA);
  160.             pokeb(VIDSEG,l160+(c<<1)+1,col);
  161.     memset(oldFFT, 0, sizeof(oldFFT));
  162.     memset(avgFFT, 0, sizeof(avgFFT));
  163.         notTotReset = TRUE;
  164.                                         // Clear the FFT results.
  165.     memset(fft, 0, sizeof(fft));
  166.     memset(totFFT, 0, sizeof(totFFT));
  167.                     if (sbOver<0xFFFF) sbOver++;
  168.                     updateDisplay();
  169. avgFFT[freqm2]+
  170.                 avgFFT[00]+
  171.     pokeb(VIDSEG, 2482+(focavg<<1), 0x20);
  172.     pokeb(VIDSEG, 2482+(oldfocavg<<1), 0x20);
  173.     pokeb(VIDSEG, 2482
  174.     pokeb(VIDSEG, 2482+(oldfocavg<<1), 0x20);
  175.     target = (totavg<<1) + offset;
  176.     pokeb(VIDSEG, 2482+(target<<1), 0x20);
  177.     totavg=    max(avgFFT[ 0],avgFFT[ 1])
  178.             max(avgFFT[ 0],avgFFT[ 1])
  179.     thisCnt++;
  180.     static int focavg=4, oldfocavg=4;
  181.     static int totavg=4, oldtotavg=4;
  182.     static int target;
  183. static    ULONG    totMark, cntMark;
  184. static    ULONG    totSpace, cntMark;
  185. static    UINT    thisLength=0;
  186. static    ULONG        totMark, cntMark, avgMark;        // mark statistics
  187. static    ULONG        totSpace, cntSpace, avgSpace;    // space statistics
  188. static    UINT        thisLength=0;                    // current stats
  189.                                         // Copy the current average FFT
  190.                                         // values to a temporary buffer for
  191.                                         // erasing the display.
  192.     memcpy(oldFFT, avgFFT, sizeof(oldFFT));
  193.                                         // Subtract the oldest FFT result
  194.                                         // from the average total.
  195.     if (notTotReset)
  196.         totFFT[ 0] -= fft[0][ 0];
  197.         totFFT[ 1] -= fft[0][ 1];
  198.         totFFT[ 2] -= fft[0][ 2];
  199.         totFFT[ 3] -= fft[0][ 3];
  200.         totFFT[ 4] -= fft[0][ 4];
  201.         totFFT[ 5] -= fft[0][ 5];
  202.         totFFT[ 6] -= fft[0][ 6];
  203.         totFFT[ 7] -= fft[0][ 7];
  204.         totFFT[ 8] -= fft[0][ 8];
  205.         totFFT[ 9] -= fft[0][ 9];
  206.         totFFT[10] -= fft[0][10];
  207.         totFFT[11] -= fft[0][11];
  208.         totFFT[12] -= fft[0][12];
  209.         totFFT[13] -= fft[0][13];
  210.         totFFT[14] -= fft[0][14];
  211.     notTotReset = TRUE;
  212.                                         // Shift the FFT buffer left one
  213.                                         // graph, erasing the oldest FFT and
  214.                                         // making room for the new one.
  215.     memmove(&(fft[0][0]), &(fft[1][0]), N*(cntFFT-1));
  216.                                         // Calculate cntFFT minus 1 for speed
  217.     cntFFTm1 = cntFFT - 1;
  218.                                         // Fill in the resulting FFT array
  219.                                         // while adding the new values to the
  220.                                         // FFT total for "cntFFT" iterations.
  221.                                         // Also calculate the average FFT at
  222.                                         // this time.
  223.     avgFFT[ 0] =
  224.         totFFT[ 0] +=
  225.                 fft[cntFFTm1][ 0] =
  226.                 (abs(s1Mf25s3f27s5f29s7f31+s2Mf26Ps4f28s6f30Ms8f16)>>SCALE)+
  227.                 (abs(s1Pf31s3f29s5f27s7f25+s2Pf30Ps4f28s6f26Ps8f24)>>SCALE)
  228.         ) / cntFFT;
  229.                     notSpaceReset = FALSE;
  230.                     totSpace += (bufspace[cntBuf-1] = thisCnt);
  231.                     totMark = cntMark = avgMark = 0;
  232.                     totSpace = cntSpace = avgSpace = 0;
  233.                     notMarkReset = FALSE;
  234.                     notSpaceReset = FALSE;
  235.                     notMarkReset = TRUE;
  236.                     notSpaceReset = FALSE;
  237.                 max
  238.                 (
  239.                     max
  240.                     (
  241.                         max(max(avgFFT[ 0],avgFFT[ 1]),max(avgFFT[ 2],avgFFT[ 3])),
  242.                         max(max(avgFFT[ 4],avgFFT[ 5]),max(avgFFT[ 6],avgFFT[ 7]))
  243.                     ),
  244.                     max
  245.                     (
  246.                         max(max(avgFFT[ 8],avgFFT[ 9]),max(avgFFT[10],avgFFT[11])),
  247.                         max(max(avgFFT[12],avgFFT[14]),avgFFT[14])
  248.                     )
  249.                 )
  250.                 max
  251.                 (
  252.                     avgFFT[freq],
  253.                     max
  254.                     (
  255.                         max(avgFFT[freqm2],avgFFT[freqm1]),
  256.                         max(avgFFT[freqp1],avgFFT[freqp2])
  257.                     )
  258.                 )
  259.     oldallavg = allavg;
  260.     oldtonedetected = tonedetected;
  261.     if (avgFFT[ 0]<offset) avgFFT[ 0] = 1;
  262.                 avgFFT[ 1]+
  263.                         alltot =    avgFFT[ 0]+
  264.                                     avgFFT[ 1]+
  265.                                     avgFFT[ 2]+
  266.                                     avgFFT[ 3]+
  267.                                     avgFFT[ 4]+
  268.                                     avgFFT[ 5]+
  269.                                     avgFFT[ 6]+
  270.                                     avgFFT[ 7]+
  271.                                     avgFFT[ 8]+
  272.                                     avgFFT[ 9]+
  273.                                     avgFFT[10]+
  274.                                     avgFFT[11]+
  275.                                     avgFFT[12]+
  276.                                     avgFFT[13]+
  277.                                     avgFFT[14]
  278. #define FLIP 5 /* levels above average sufficient to trigger tone detected */
  279. #define LOG2N 4 /* Adjust according to N way above */ 
  280. static int tonedetected=FALSE; /* indicates a tone is currently present */
  281. static int freqm2,freqm1,freqp1,freqp2,freq=(N>>1); /* interesting frequency */
  282. void FFT2tone(void)
  283. { /* determines whether a morse tone is present or not */
  284.   static int old3active,old2active=FALSE,old1active=FALSE,active=FALSE; 
  285.   static int average,l,limit,oldtonedetected;
  286.   average=0;
  287.   for (l=1 ; l<N ; l++) average+=fft[l];
  288.   average>>=LOG2N;
  289.   limit=FLIP+(5*average);
  290.   old3active=old2active;
  291.   old2active=old1active;
  292.   old1active=active;
  293.   active=( (fft[freqm2]+fft[freqp2]+fft[freqm1]+fft[freqp1]+fft[freq])>=limit );
  294.   oldtonedetected=tonedetected;
  295.   tonedetected=(active || old1active || old2active || old3active);
  296.   if (tonedetected && !oldtonedetected) pokeb(videoseg,158,'
  297.   else if (oldtonedetected && !tonedetected) pokeb(videoseg,158,'
  298.                 avgFFT[freqm1]+
  299.                 avgFFT[ 0]+
  300.     pokeb(VIDSEG, 2482+(target<<1), 0x20);
  301.                 avgFFT[ 0]+
  302.                 avgFFT[ 1]+
  303.                 avgFFT[ 2]+
  304.                 avgFFT[ 3]+
  305.                 avgFFT[ 4]+
  306.                 avgFFT[ 5]+
  307.                 avgFFT[ 6]+
  308.                 avgFFT[ 7]+
  309.                 avgFFT[ 8]+
  310.                 avgFFT[ 9]+
  311.                 avgFFT[10]+
  312.                 avgFFT[11]+
  313.                 avgFFT[12]+
  314.                 avgFFT[13]+
  315.                 avgFFT[14]
  316. ((morse==MORSE_MORSE)?("morse)."):((morse==MORSE_TEXT)?("text )."):("tone ).")))
  317. enum MORSE_TYPES
  318.     MORSE_MORSE, MORSE_TEXT, MORSE_TONE, MORSE_MAX
  319.                     push ax                // save the registers we're using
  320.                     push bx
  321.                     push cx
  322.                     push ds
  323.                     push es
  324.                     push di
  325.                     push si
  326.         nosound();
  327.     freqp1 = freq + 1;
  328.     pokeb(VIDSEG,(74-160)+(160*freqm2),c1);
  329.     pokeb(VIDSEG,(74-160)+(160*freqm1),c1);
  330.     pokeb(VIDSEG,(74-160)+(160*freq),c1);
  331.     pokeb(VIDSEG,(74-160)+(160*freqp1),c1);
  332.     pokeb(VIDSEG,(74-160)+(160*freqp2),c1);
  333.     pokeb(VIDSEG,(76-160)+(160*freqm2),c2);
  334.     pokeb(VIDSEG,(76-160)+(160*freqm1),c2);
  335.     pokeb(VIDSEG,(76-160)+(160*freq),c2);
  336.     pokeb(VIDSEG,(76-160)+(160*freqp1),c2);
  337.     pokeb(VIDSEG,(76-160)+(160*freqp2),c2);
  338.     pokeb(VIDSEG,(74-160)+(160*freqm2),c1);
  339.     pokeb(VIDSEG,(74-160)+(160*freqm1),c1);
  340.     pokeb(VIDSEG,(74-160)+(160*freq),c1);
  341.     pokeb(VIDSEG,(74-160)+(160*freqp1),c1);
  342.     pokeb(VIDSEG,(74-160)+(160*freqp2),c1);
  343.     pokeb(VIDSEG,(74-160)+(160*outm1), c1);
  344.                                         // Clear the audio spectrum analyzer
  345.                                         // on the screen.
  346.     for (l=0,l160=0; l<(N-1); l++,l160+=160)
  347.         for (c=41; c<GRAPHTOP; c++)
  348.             if        (c<BLU)    col=9;
  349.             else if (c<GRN)    col=10;
  350.             else if (c<YEL)    col=14;
  351.             else            col=12;
  352.             pokeb(VIDSEG,l160+(c<<1),0xFA);
  353.             pokeb(VIDSEG,l160+(c<<1)+1,col);
  354.             if        (c<BLU)    col=9;
  355.             else if (c<GRN)    col=10;
  356.             else if (c<YEL)    col=14;
  357.             else            col=12;
  358.             pokeb(VIDSEG,l160+(c<<1),0xFA);
  359.             pokeb(VIDSEG,l160+(c<<1)+1,col);
  360.             pokeb(VIDSEG,(outm1*160)+(c<<1)+1,0x10);
  361.             pokeb(VIDSEG,(outm1*160)+(c<<1)+1,col);
  362.             if        (c<BLU)    col=9;
  363.             else if (c<GRN)    col=10;
  364.             else if (c<YEL)    col=14;
  365.             else            col=12;
  366.                                         // Tune out that graph portion.
  367.     for (c=41; c<GRAPHTOP; c++)
  368.         if (onoff)
  369.             col=16;
  370.         else
  371.             if        (c<BLU)    col=9;
  372.             else if (c<GRN)    col=10;
  373.             else if (c<YEL)    col=14;
  374.             else            col=12;
  375.         pokeb(VIDSEG,(outm1*160)+(c<<1)+1,col);
  376.         pokeb(VIDSEG,(out*160)+(c<<1)+1,col);
  377.         pokeb(VIDSEG,(outp1*160)+(c<<1)+1,col);
  378.         pokeb(VIDSEG,(outm1*160)+(c<<1)+1,col);
  379.         pokeb(VIDSEG,(out*160)+(c<<1)+1,col);
  380.             if        (c<BLU)    col=1;        // 9
  381.             else if (c<GRN)    col= 2;        // 10
  382.             else if (c<YEL)    col= 6;        // 14
  383.             else            col= 4;        // 12
  384.             if        (c<BLU)    col=1;        // 9
  385.             else if (c<GRN)    col= 2;        // 10
  386.             else if (c<YEL)    col= 6;        // 14
  387.             else            col= 4;        // 12
  388.             if        (c<BLU)    col=9;
  389.             else if (c<GRN)    col=10;
  390.             else if (c<YEL)    col=14;
  391.             else            col=12;
  392.             if        (c<BLU)    col=1;        // 9
  393.             else if (c<GRN)    col= 2;        // 10
  394.             else if (c<YEL)    col= 6;        // 14
  395.             else            col= 4;        // 12
  396.                     alltot=    (
  397.                                 avgFFT[ 0]+
  398.                                 avgFFT[ 1]+
  399.                                 avgFFT[ 2]+
  400.                                 avgFFT[ 3]+
  401.                                 avgFFT[ 4]+
  402.                                 avgFFT[ 5]+
  403.                                 avgFFT[ 6]+
  404.                                 avgFFT[ 7]+
  405.                                 avgFFT[ 8]+
  406.                                 avgFFT[ 9]+
  407.                                 avgFFT[10]+
  408.                                 avgFFT[11]+
  409.                                 avgFFT[12]+
  410.                                 avgFFT[13]+
  411.                             )
  412.             gotoxy(1,1); cprintf("%d %d   ", freq, out);
  413. /////////////////////////////////////////////////////////////////////////////
  414. void updateCursors(char onoff)
  415.     char c1, c2;
  416.     int c, col;
  417.                                         // Determine the cursor characters.
  418.     if (onoff)
  419.         c1 = '<';
  420.         c2 = '>';
  421.     else
  422.         c1 = c2 = ' ';
  423.                                         // Calculate the focus cursor range.
  424.     freqm2 = freq - 2;
  425.     freqm1 = freq - 1;
  426.     freqp1 = freq + 1;
  427.     freqp2 = freq + 2;
  428.                                         // Calculate the tuned-out cursor.
  429.     outm1 = out - 1;
  430.     outp1 = out + 1;
  431.                                         // Display the tuned-out cursor.
  432.     pokeb(VIDSEG,(74)+(160*outm1), c1);
  433.     pokeb(VIDSEG,(74)+(160*out), c1);
  434.     pokeb(VIDSEG,(74)+(160*outp1), c1);
  435.                                         // Tune out that graph portion.
  436.     for (c=41; c<GRAPHTOP; c++)
  437.         if (tuneout && onoff)
  438.             col=8;
  439.         else
  440.             if        (c<BLU)    col=9;
  441.             else if (c<GRN)    col=10;
  442.             else if (c<YEL)    col=14;
  443.             else            col=12;
  444.         pokeb(VIDSEG,((outm1)*160)+(c<<1)+1,col);
  445.         pokeb(VIDSEG,((out)*160)+(c<<1)+1,col);
  446.         pokeb(VIDSEG,((outp1)*160)+(c<<1)+1,col);
  447.                                         // Display the frequency cursor.
  448.     pokeb(VIDSEG,(76)+(160*freqm2),c2);
  449.     pokeb(VIDSEG,(76)+(160*freqm1),c2);
  450.     pokeb(VIDSEG,(76)+(160*freq),c2);
  451.     pokeb(VIDSEG,(76)+(160*freqp1),c2);
  452.     pokeb(VIDSEG,(76)+(160*freqp2),c2);
  453.                                         // Focus on the graph bit.
  454.     for (c=41; c<GRAPHTOP; c++)
  455.         if        (c<BLU)    col=9;
  456.         else if (c<GRN)    col=10;
  457.         else if (c<YEL)    col=14;
  458.         else            col=12;
  459.         if (onoff)
  460.             col |= 0x68;
  461.         pokeb(VIDSEG,((freqm2)*160)+(c<<1)+1,col);
  462.         pokeb(VIDSEG,((freqm1)*160)+(c<<1)+1,col);
  463.         pokeb(VIDSEG,((freq)*160)+(c<<1)+1,col);
  464.         pokeb(VIDSEG,((freqp1)*160)+(c<<1)+1,col);
  465.         pokeb(VIDSEG,((freqp2)*160)+(c<<1)+1,col);
  466.             asm {
  467.                 push ax                    // save the registers we're using
  468.                 push bx
  469.                 push cx
  470.                 push ds
  471.                 push es
  472.                 push di
  473.                 push si
  474.                 mov bx, 0x01            // line to scroll into
  475.                 mov ax, VIDSEG            // source and destionation segments
  476.                 push ax
  477.                 push ax
  478.                 pop ds
  479.                 pop es
  480. lineloop:
  481.             asm {
  482.                 mov ax, 0x00A0            // calculate offset of dest line
  483.                 mul bl
  484.                 inc ax
  485.                 inc ax
  486.                 mov di, ax
  487.                 cmp bx, 0x17            // see if we're done
  488.                 je scrolldone            // leave the scroll if so
  489.                 add ax, 0xA0            // calculate offset of source
  490.                 mov si, ax
  491.                 mov cx, 0x22            // number of WORDS to move
  492.                 rep movsw                // move them
  493.                 inc bx                    // go to the next line
  494.                 jmp lineloop            // loop around to calculate it
  495. scrolldone:
  496.             asm {
  497.                 mov ax, 0x0720            // word to clear a display character
  498.                 mov cx, 0x22            // number of words to erase
  499.                 rep stosw
  500.                 pop si                    // restore the registers we've saved
  501.                 pop di
  502.                 pop es
  503.                 pop ds
  504.                 pop cx
  505.                 pop bx
  506.                 pop ax
  507.             x=1;
  508. #define BOXTOP    0x00                    // 0-based line of box top
  509. #define BOXDIV    0x0B                    // 0-based line of box divider
  510. #define BOXBOT    0x17                    // 0-based line of box bottom
  511.     pokeb(VIDSEG,(160*BOXTOP)+(BOXLEF<<1),0xDA);
  512.                         morsePutC(0x20);
  513. /////////////////////////////////////////////////////////////////////////////
  514. //    Put a character into the text window.
  515. void textPutC(char c)
  516.     static int x=1, y=23;
  517.     pokeb(VIDSEG,(x<<1)+(y*160), c);
  518.     x++;
  519.     if (x>=35)
  520.             asm {
  521.                 push ax                    // save the registers we're using
  522.                 push bx
  523.                 push cx
  524.                 push dx
  525.                 push ds
  526.                 push es
  527.                 push di
  528.                 push si
  529.                                         // line to scroll into
  530.                 mov bx, BOXTOP+1
  531.                                         // source and destination segments
  532.                 mov ax, VIDSEG
  533.                 push ax
  534.                 push ax
  535.                 pop ds
  536.                 pop es
  537. lineloop:
  538.             asm {
  539.                                         // calculate dest line offset
  540.                 mov ax, 0x00A0
  541.                 mul bl
  542.                                         // calculate the left window inside
  543.                 mov dx, BOXLEF
  544.                 inc dx
  545.                 shl dx, 1
  546.                                         // combine them
  547.                 add ax, dx
  548.                 cmp bx, BOXDIV-1        // see if we're done
  549.                 je scrolldone            // leave the scroll if so
  550.                 add ax, 0xA0            // calculate offset of source
  551.                 mov si, ax
  552.                 mov cx, 0x22            // number of WORDS to move
  553.                 rep movsw                // move them
  554.                 inc bx                    // go to the next line
  555.                 jmp lineloop            // loop around to calculate it
  556. scrolldone:
  557.             asm {
  558.                 mov ax, 0x0720            // word to clear a display character
  559.                 mov cx, 0x22            // number of words to erase
  560.                 rep stosw
  561.                 pop si                    // restore the registers we've saved
  562.                 pop di
  563.                 pop es
  564.                 pop ds
  565.                 pop dx
  566.                 pop cx
  567.                 pop bx
  568.                 pop ax
  569.             x=1;
  570.     pokeb(VIDSEG,(x<<1)+((BOXDIV-1)*160), c);
  571.     pokeb(VIDSEG,(x<<1)+((BOXBOT-1)*160), c);
  572.                         if (thisCnt >= (useSpace*3))
  573.                         {
  574.                             textPutC(0x20);
  575.                         }
  576.                         morsePutC(0x20);
  577.                         morsePutC('-');
  578.                         morsePutC(0xF9);
  579.                                         // Update periodical display stuff.
  580.         updateDisplay();
  581.                                         // Show new sample rate
  582.                 updateDisplay();
  583.     morsePutC(0x20);
  584.     morsePutC(0x20);
  585.     morsePutC(0x20);
  586. /////////////////////////////////////////////////////////////////////////////
  587. //    Add a character to the tone line.
  588. void tonePutC(char c)
  589.     // scroll the tone line (bottom) left
  590.     // add a character at the end of the line
  591.     asm {
  592.                                         // Save registers
  593.         push ax
  594.         push bx
  595.         push cx
  596.         push ds
  597.         push es
  598.         push di
  599.         push si
  600.                                         // source and destination segments
  601.         mov ax, VIDSEG
  602.         push ax
  603.         push ax
  604.         pop ds
  605.         pop es
  606.                                         // Dest & source offsets
  607.         mov di, 0x0F00
  608.         mov si, 0x0F02
  609.                                         // Set the move count (words)
  610.         mov cx, 0x004F
  611.                                         // Move the junk
  612.         rep movsw
  613.                                         // Restore registers
  614.         pop si
  615.         pop di
  616.         pop es
  617.         pop ds
  618.         pop cx
  619.         pop bx
  620.         pop ax
  621.     pokeb(VIDSEG, (160*25)-2, c);
  622. /////////////////////////////////////////////////////////////////////////////
  623. //    Put a character into the text window.
  624. void textPutC(char c)
  625.     static int x=BOXLEF+1;
  626.     pokeb(VIDSEG,(x<<1)+((BOXDIV-1)*160), c);
  627.     if ((++x)>=BOXRIG)
  628.             asm {
  629.                 push ax                    // save the registers we're using
  630.                 push bx
  631.                 push cx
  632.                 push dx
  633.                 push ds
  634.                 push es
  635.                 push di
  636.                 push si
  637.                                         // line to scroll into
  638.                 mov bx, BOXTOP+1
  639.                                         // source and destination segments
  640.                 mov ax, VIDSEG
  641.                 push ax
  642.                 push ax
  643.                 pop ds
  644.                 pop es
  645. lineloop:
  646.             asm {
  647.                                         // calculate dest line offset
  648.                 mov ax, 0x00A0
  649.                 mul bl
  650.                                         // calculate the left window inside
  651.                 mov dx, BOXLEF
  652.                 inc dx
  653.                 shl dx, 1
  654.                                         // combine them
  655.                 add ax, dx
  656.                 mov di, ax
  657.                 cmp bx, BOXDIV-1        // see if we're done
  658.                 je scrolldone            // leave the scroll if so
  659.                 add ax, 0xA0            // calculate offset of source
  660.                 mov si, ax
  661.                 mov cx,(BOXRIG-BOXLEF)-1
  662.                 rep movsw                // move them
  663.                 inc bx                    // go to the next line
  664.                 jmp lineloop            // loop around to calculate it
  665. scrolldone:
  666.             asm {
  667.                                         // AX = word to clear; CX = count
  668.                 mov ax, 0x0720
  669.                 mov cx, (BOXRIG-BOXLEF)-1
  670.                 rep stosw                // clear the last line in the window
  671.                 pop si                    // restore the registers we've saved
  672.                 pop di
  673.                 pop es
  674.                 pop ds
  675.                 pop dx
  676.                 pop cx
  677.                 pop bx
  678.                 pop ax
  679.             x=BOXLEF+1;
  680. /////////////////////////////////////////////////////////////////////////////
  681. //    Put a character into the morse window.
  682. void morsePutC(char c)
  683.     static int x=BOXLEF+1;
  684.     pokeb(VIDSEG,(x<<1)+((BOXBOT-1)*160), c);
  685.     if ((++x)>=BOXRIG)
  686.             asm {
  687.                 push ax                    // save the registers we're using
  688.                 push bx
  689.                 push cx
  690.                 push dx
  691.                 push ds
  692.                 push es
  693.                 push di
  694.                 push si
  695.                                         // line to scroll into
  696.                 mov bx, BOXDIV+1
  697.                                         // source and destination segments
  698.                 mov ax, VIDSEG
  699.                 push ax
  700.                 push ax
  701.                 pop ds
  702.                 pop es
  703. lineloop:
  704.             asm {
  705.                                         // calculate dest line offset
  706.                 mov ax, 0x00A0
  707.                 mul bl
  708.                                         // calculate the left window inside
  709.                 mov dx, BOXLEF
  710.                 inc dx
  711.                 shl dx, 1
  712.                                         // combine them
  713.                 add ax, dx
  714.                 mov di, ax
  715.                 cmp bx, BOXBOT-1        // see if we're done
  716.                 je scrolldone            // leave the scroll if so
  717.                 add ax, 0xA0            // calculate offset of source
  718.                 mov si, ax
  719.                                         // word count to move
  720.                 mov cx, (BOXRIG-BOXLEF)-1
  721.                 rep movsw                // move them
  722.                 inc bx                    // go to the next line
  723.                 jmp lineloop            // loop around to calculate it
  724. scrolldone:
  725.             asm {
  726.                                         // AX = clear word; CX = word count
  727.                 mov ax, 0x0720
  728.                 mov cx, (BOXRIG-BOXLEF)-1
  729.                 rep stosw
  730.                 pop si                    // restore the registers we've saved
  731.                 pop di
  732.                 pop es
  733.                 pop ds
  734.                 pop dx
  735.                 pop cx
  736.                 pop bx
  737.                 pop ax
  738.             x=(BOXLEF+1);
  739.         pokeb(VIDSEG, 158, 0xEC);
  740. //    Display a character in the "tone" display across the screen bottom.
  741. void tonePutC(char c)
  742.     // scroll the tone line (bottom) left
  743.     // add a character at the end of the line
  744.     asm {
  745.                                         // Save registers
  746.         push ax
  747.         push bx
  748.         push cx
  749.         push ds
  750.         push es
  751.         push di
  752.         push si
  753.                                         // source and destination segments
  754.         mov ax, VIDSEG
  755.         push ax
  756.         push ax
  757.         pop ds
  758.         pop es
  759.                                         // Dest & source offsets
  760.         mov di, 0x0F00
  761.         mov si, 0x0F02
  762.                                         // Set the move count (words)
  763.         mov cx, 0x004F
  764.                                         // Move the junk
  765.         rep movsw
  766.                                         // Restore registers
  767.         pop si
  768.         pop di
  769.         pop es
  770.         pop ds
  771.         pop cx
  772.         pop bx
  773.         pop ax
  774.     pokeb(VIDSEG, (160*25)-2, c);
  775.                     if (useSpace>1)
  776.                     {
  777.                         useSpace--;
  778.                         updateDisplay();
  779.                     }
  780.                     break;
  781.                     if (useSpace>100)
  782.                     {
  783.                         useSpace -= 100;
  784.                         updateDisplay();
  785.                     }
  786.                     break;
  787.                     if (useSpace<2000)
  788.                     {
  789.                         useSpace++;
  790.                         updateDisplay();
  791.                     }
  792.                     break;
  793.                     if (useSpace<9999)
  794.                     {
  795.                         useSpace++;
  796.                         updateDisplay();
  797.                     }
  798.                     break;
  799.                     if (thrNoise>1)
  800.                     {
  801.                         thrNoise--;
  802.                         updateDisplay();
  803.                     }
  804.                     break;
  805.                     if (thrNoise<9999)
  806.                     {
  807.                         thrNoise++;
  808.                         updateDisplay();
  809.                     }
  810.                     break;
  811.                     if (useMark>1)
  812.                     {
  813.                         useMark--;
  814.                         updateDisplay();
  815.                     }
  816.                     break;
  817.                     if (useMark<9999)
  818.                     {
  819.                         useMark++;
  820.                         updateDisplay();
  821.                     }
  822.                     break;
  823.         f[k]=(*(dsp+=waitfactor))-128;
  824.     f[k]=(*(dsp+=waitfactor))-128;
  825.     f[ k]=(*(dsp+=waitfactor))-128;
  826.                     memmove(bufSpace, bufSpace+1, cntBuf-1);
  827.                     avgSpace = (totSpace += (bufSpace[cntBuf-1] = thisCnt))/cntBuf;
  828.